package io.renren.modules.weixin.message.responsemsg;

import io.renren.common.utils.Constant;
import io.renren.modules.weixin.util.MessageBuilder;

import java.util.Calendar;

/**
 * @Author: zhangxinlin
 * @Description:  回复文本消息
 * @param null
 * @Date: 16:59 2018/1/24
 */
public final class TextMsg extends BaseMsg {

    private StringBuilder contentBuilder;

    public TextMsg() {
        contentBuilder = new StringBuilder();
    }

    public TextMsg(String content) {
        setContent(content);
    }

    public String getContent() {
        return contentBuilder.toString();
    }

    public void setContent(String content) {
        contentBuilder = new StringBuilder(content);
    }

    public TextMsg add(String text) {
        contentBuilder.append(text);
        return this;
    }

    public TextMsg addln() {
        return add("\n");
    }

    public TextMsg addln(String text) {
        contentBuilder.append(text);
        return addln();
    }

    public TextMsg addLink(String text, String url) {
        contentBuilder.append("<a href=\"").append(url).append("\">")
                .append(text).append("</a>");
        return this;
    }

    @Override
    public String toXml() {
        MessageBuilder mb = new MessageBuilder(super.toXml());
        mb.addData("Content", contentBuilder.toString().trim());
        mb.addData("MsgType", Constant.RespType.TEXT);
        mb.surroundWith("xml");
        return mb.toString();
    }

    public static void main(String[] args) {
        TextMsg test = new TextMsg();
        test.setToUserName("sldfjalsd;fas");
        test.setFromUserName("appid");
        test.setContent("s手动阀是的卡受理的sdls");
        test.setCreateTime(Calendar.getInstance().getTimeInMillis());
        System.out.println(test.toXml());
    }

}
